import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common';
import { ShopUsersService } from './shop-users.service';
import { CreateShopUserDto, ListShopUsersDto, LoginDto, UpdateShopUsersDto } from './dto/shop-users.dto';
import { query } from 'express';
import { RequirePermission } from 'src/common/decorators/require-premission.decorator';
import { User } from 'src/module/system/user/user.decorator';

@Controller('shop/users')
export class ShopUsersController {
  constructor(private readonly shopUserService: ShopUsersService) {}

  @RequirePermission('shop:user:add')
  @Post()
  create(@Body() shopUser: CreateShopUserDto) {
    return this.shopUserService.create(shopUser);
  }

  @Post('login')
  login(@Body() data: LoginDto) {
    return this.shopUserService.appLogin(data);
  }

  @RequirePermission('shop:user:list')
  @Get('list')
  findAll(@Query() query: ListShopUsersDto) {
    return this.shopUserService.findAll(query);
  }

  @RequirePermission('shop:user:query')
  @Get(':id')
  findOne(@Param('id') id: number, @User() user: Record<string, any>) {
    console.log(user);
    return this.shopUserService.findOne(id);
  }

  @RequirePermission('shop:user:delete')
  @Delete(':id')
  remove(@Param('id') id: number) {
    return this.shopUserService.remove(id);
  }
  @RequirePermission('shop:user:update')
  @Put()
  update(@Body() data: UpdateShopUsersDto) {
    return this.shopUserService.update(data);
  }
}
